package com.liujun.spring4.demo.aop.application.property.outerconfig;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;

/**
 * 模拟使用外部的配制来初始化此数据，然后加载到表中
 *
 * @author liujun
 * @version 0.0.1
 * @date 2018/09/06
 */
public class SysConfig {

  private int sessionTimeout;

  private int maxTablePageNum;

  private DataSource dataource;

  public void initFormDb() {
    try {
      Connection conn = dataource.getConnection();

      Map<String, String> rs = DatabaseProcess.INSTANCE.getConfig(conn);

      sessionTimeout = Integer.parseInt(rs.get("sessionTimeout"));
      maxTablePageNum = Integer.parseInt(rs.get("maxTablePageNum"));

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }

  public int getSessionTimeout() {
    return sessionTimeout;
  }

  public int getMaxTablePageNum() {
    return maxTablePageNum;
  }

  public void setDataource(DataSource dataource) {
    this.dataource = dataource;
  }
}
